/*********** tuannh ****************
 function : snap setting
***********************************/
function init_SnapSettings() {
    // Tolerance
    var txtTolerance = _getElementById('txtTolerance');
    if (Snap_Array.length > 0) txtTolerance.value = Snap_Array[0].Tolerance;

    // Setting Snap
    // body
    var tbody = $('#tbodySettingSnap');
    var i = 0, snapObj = null;
    var trBody = null, tdBody_LayerName = null, tdBody_Node = null, tdBody_Vertex = null, tdBody_Edge = null;
    var inputBody_Node = null, inputBody_Vertex = null, inputBody_Edge = null;
    for (i = 0; i < Snap_Array.length; i++) {
        snapObj = Snap_Array[i];
        trBody = document.createElement('tr');
        // layer name
        tdBody_LayerName = document.createElement('td');
        //tdBody_LayerName.style.width = '100px';
        tdBody_LayerName.innerText = Vector_Array[snapObj.IndexLayer - numBaseLayer].Layer_Name;
        trBody.appendChild(tdBody_LayerName);
        // node
        tdBody_Node = document.createElement('td');
        inputBody_Node = document.createElement('input');
        inputBody_Node.type = 'checkbox';
        inputBody_Node.id = 'chk' + i.toString() + '_Node';
        tdBody_Node.appendChild(inputBody_Node);
        if (snapObj.Node) inputBody_Node.checked = true;
        else inputBody_Node.checked = false;    
        inputBody_Node.value = snapObj.IndexLayer - 1 + "|node";
        inputBody_Node.onclick = input_Click;
        trBody.appendChild(tdBody_Node);
        // vertex
        tdBody_Vertex = document.createElement('td');
        inputBody_Vertex = document.createElement('input');
        inputBody_Vertex.type = 'checkbox';
        inputBody_Vertex.id = 'chk' + i.toString() + '_Vertex';
        tdBody_Vertex.appendChild(inputBody_Vertex);
        if (snapObj.Vertex) inputBody_Vertex.checked = true;
        else inputBody_Vertex.checked = false;    
        inputBody_Vertex.value = snapObj.IndexLayer - 1 + "|vertex";
        inputBody_Vertex.onclick = input_Click;
        trBody.appendChild(tdBody_Vertex);
        // edge
        tdBody_Edge = document.createElement('td');
        inputBody_Edge = document.createElement('input');
        inputBody_Edge.type = 'checkbox';
        inputBody_Edge.id = 'chk' + i.toString() + '_Edge';
        tdBody_Edge.appendChild(inputBody_Edge);
        if (snapObj.Edge) inputBody_Edge.checked = true;
        else inputBody_Edge.checked = false;    
        inputBody_Edge.value = snapObj.IndexLayer - 1 + "|edge";
        inputBody_Edge.onclick = input_Click;
        trBody.appendChild(tdBody_Edge);
        tbody.append(trBody);
        //tbody.appendChild(trBody);
    }

    $(_divSnap).css('backgroundColor', '#F0F8FF');
    //_divSnap.style.backgroundColor = "#F0F8FF";
}

function input_Click() {
    var objValue = this.value;
    objValue = objValue.split('|');
    var index = objValue[0];
    var objName = objValue[1];
    switch (objName) {
        case 'node':
            Snap_Array[index].Node = this.checked;
            break;
        case 'vertex':
            Snap_Array[index].Vertex = this.checked;
            break;
        case 'edge':
            Snap_Array[index].Edge = this.checked;
            break;
    }
}

function SnapSetting_Click() {
    //alert('ok');
    var i = 0, j = 0;
    var objTolerance = _getElementById('txtTolerance');
    if (objTolerance.value == '') {
        alert('Báº¡n cáº§n chá»�n khoáº£ng cÃ¡ch Ä‘á»ƒ báº¯t Ä‘á»‘i tÆ°á»£ng');
        objTolerance.focus();
        return false;
    }
    var snapObj = null;
    for (i = 0; i < Snap_Obj.length; i++) {
        snapObj = Snap_Obj[i];
        for (j = 0; j < snapObj.targets.length; j++) {
            snapObj.targets[j].node = Snap_Array[j].Node;
            snapObj.targets[j].nodeTolerance = objTolerance.value;
            snapObj.targets[j].vertex = Snap_Array[j].Vertex;
            snapObj.targets[j].vertexTolerance = objTolerance.value;
            snapObj.targets[j].edge = Snap_Array[j].Edge;
            snapObj.targets[j].edgeTolerance = objTolerance.value;
        }
    }
}

function SnapSetting_Close_Click() {
    $(_divSnap).css('display', 'none');
}

// snap init
function loadSnaping()
{
	for (var i = 0; i < iNum_Vector; i++) {
	    var snap = new Snap_Settings((i + 1), Tolerance, Node, Vertex, Edge);
	    Snap_Array[Snap_Array.length] = snap;
	}	
}
/******* end function **********/